"use strict";

/**
 * author:Administrator
 * date:2015/11/30
 * desc: user face dao
 */
var Model = require('../model/face_star.js');
var dao = {};

module.exports = dao;

/**
 * save
 * @param json {object}
 */
dao.save = function *(json) {
  var entity = new Model({
    starid: json.starid,
    name: json.name,
    path: json.path,
    rpath: json.rpath
  });

  return yield entity.save();
};

dao.getAll = function*() {
  return yield Model.find();
};

dao.updateName = function *(starid, name) {
  return yield Model.findOneAndUpdate(
    {starid: starid},
    {$set: {name: name}},
    {upsert: true, 'new': true});
};

dao.cleanCollection = function*() {
  return yield Model.remove({});
};